package com.coldwindblows.blog.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.coldwindblows.blog.utils.TaleUtils;

/**
 * 向mvc中添加自定义组件
 * @author Administrator
 *
 */
@Component
public class WebMvcConfig extends WebMvcConfigurerAdapter {

	@Autowired
	private BaseInterceptor baseInterceptor;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(baseInterceptor);
	}
	
	/**
	 * 添加静态资源文件，外部可以直接访问地址
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/upload/**").addResourceLocations("file:" + TaleUtils.getUploadFilePath() + "upload/");
		super.addResourceHandlers(registry);
	}
}
